package com.twu.biblioteca.library.controllers;
import com.twu.biblioteca.Persistence.MovieRepository;
import com.twu.biblioteca.Persistence.ItemsRepository;
import com.twu.biblioteca.library.items.Movie;

/**
 * Created by aruna on 27/4/14.
 */
public class MovieReservationManager {
    private static final MovieRepository Repository =new MovieRepository();
    public MovieRepository getMoviesRepository() { return Repository; }

    //Handles User stories 6,7,8
    public static String checkOut(String ISBN) {
        String success_message="Thank you! Enjoy the movie";
        String failure_message="That movie is not available";
        ItemsRepository<Movie> repository= Repository.getMovieSet();
        if(repository.isValidItem(ISBN))
        {
            Movie movie=(Movie)repository.getItemByID(ISBN);
            if(!movie.isItemcheckedOut()) {
                movie.checkOutItem();
                movie.setIscheckedOut(true);
                return success_message;
            }

        }
        return failure_message;

    }
    //Handles User Stories 9,10,11
    public static String returnmovie(String ISBN)
    {
        String movieReturn_response="";
        ItemsRepository<Movie> repository= Repository.getMovieSet();
        if( repository.isItemAvailable(ISBN) || (!(repository.isValidItem(ISBN))))
            movieReturn_response="That is not a valid movie to return";
        else
        {
            repository.getItemByID(ISBN).returnItem();
            movieReturn_response="Thank you for returning the movie";
        }

        return movieReturn_response;
    }
}
